# from pyecharts.charts import Line
# from pyecharts.options import TitleOpts,LegendOpts,ToolboxOpts,VisualMapOpts
# line=Line()
# line.add_xaxis(["中国","美国","日本"])
# line.add_yaxis("GDP",[30,20,10])
# line.set_global_opts(
#     title_opts=TitleOpts(title="GDP展示",pos_left="center",pos_bottom="1%"),
#     legend_opts=LegendOpts(is_show=True),
#     toolbox_opts=ToolboxOpts(is_show=True),
#     visualmap_opts=VisualMapOpts(is_show=True),
# )
# line.render()
# ===========================================
# 数据可视化案例
import json
from pyecharts.charts import Line
from pyecharts.options import TitleOpts,LegendOpts,ToolboxOpts,VisualMapOpts,LabelOpts
f_us=open("C:\可视化案例数据\折线图数据\美国.txt","r",encoding="UTF-8")
f_jp=open("C:\可视化案例数据\折线图数据\日本.txt","r",encoding="UTF-8")
f_in=open("C:\可视化案例数据\折线图数据\印度.txt","r",encoding="UTF-8")

us_data=f_us.read()
jp_data=f_jp.read()
in_data=f_in.read()

us_data=us_data.replace("jsonp_1629344292311_69436(","")
us_data=us_data[:-2]
us_dict=json.loads(us_data)
trend_data=us_dict["data"][0]["trend"]
x_us_data=trend_data["updateDate"][:314]
y_us_data=trend_data["list"][0]['data'][:314]

jp_data=jp_data.replace("jsonp_1629350871167_29498(","")
jp_data=jp_data[:-2]
jp_dict=json.loads(jp_data)
trend_data=jp_dict["data"][0]["trend"]
x_jp_data=trend_data["updateDate"][:314]
y_jp_data=trend_data["list"][0]['data'][:314]

in_data=in_data.replace("jsonp_1629350745930_63180(","")
in_data=in_data[:-2]
in_dict=json.loads(in_data)
trend_data=in_dict["data"][0]["trend"]
x_in_data=trend_data["updateDate"][:314]
y_in_data=trend_data["list"][0]['data'][:314]

line=Line()
line.add_xaxis(x_us_data)

line.add_yaxis("美国确诊人数",y_us_data,label_opts=LabelOpts(is_show=False))
line.add_yaxis("日本确诊人数",y_jp_data,label_opts=LabelOpts(is_show=False))
line.add_yaxis("印度确诊人数",y_in_data,label_opts=LabelOpts(is_show=False))

line.set_global_opts(
    title_opts=TitleOpts(title="2020年美日印三国确诊人数",pos_left="center",pos_bottom="1%")
)
line.render("2020年美日印三国确诊人数.html")

f_us.close()
f_jp.close()
f_in.close()
# ===========================================================
# # 全国疫情地图案例 in 判断序列中是否存在值
# import json
# from pyecharts.charts import Map
# from pyecharts.options import *
# f=open("C:\疫情.txt","r",encoding="UTF-8")
# data=f.read()
# f.close()
# data_dict=json.loads(data)
# province_data_list=data_dict["areaTree"][0]["children"]
# data_list=[]
# for province_data in province_data_list:
#     province_name=province_data["name"]
#     province_confirm=province_data["total"]["confirm"]
#
#     # 处理省份不匹配问题
#     if province_name == "新疆":
#         province_name = "新疆维吾尔自治区"
#     elif province_name == "广西":
#         province_name = "广西壮族自治区"
#     elif province_name == "宁夏":
#         province_name = "宁夏回族自治区"
#     elif province_name in ["内蒙古", "西藏"]:
#         province_name = province_name + "自治区"
#     elif province_name in ["北京", "天津", "重庆", "上海"]:
#         province_name = province_name + "市"
#     elif province_name in ["香港", "澳门"]:
#         province_name = province_name + "特别行政区"
#     else:
#         province_name = province_name + "省"
#
#     data_list.append((province_name,province_confirm))
#
#
#
# print(data_list)
#
# map=Map()
# map.add("各省确诊人数", data_list,"china")
# map.set_global_opts(
#     title_opts=TitleOpts(title="全国疫情地图"),
#     visualmap_opts=VisualMapOpts(
#         is_show=True,
#         is_piecewise=True,
#         pieces=[
#             {"min":1,"max":99,"lable":"1~99人","color":"#CCFFFF"},
#             {"min":100,"max":999,"lable":"100~999人","color":"#FFFF99"},
#             {"min":1000,"max":4999,"lable":"1000~4999人","color":"#FF9966"},
#             {"min":5000,"max":9999,"lable":"5000~9999人","color":"#FF6666"},
#             {"min":10000,"max":99999,"lable":"10000~99999人","color":"#CC3333"},
#             {"min":100000,"lable":"100000+人","color":"#990033"},
#         ]
#     )
# )
# map.render("全国疫情图.html")
# from pyecharts.charts import Map
# map=Map()
# data=[
#     ("北京市",99),
#     ("上海市",199),
#     ("湖南省",299),
#     ("台湾省",399),
# ]
# map.add("测试map",data,"china")
# map.render("测试.html")
# # 河南省的疫情
# import json
# from pyecharts.charts import Map
# from pyecharts.options import *
# f=open("C:/疫情.txt","r",encoding="UTF-8")
# data=f.read()
# f.close()
# data_dict=json.loads(data)
# cites_data=data_dict["areaTree"][0]['children'][3]["children"]
# data_list=[]
# for city_data in cites_data:
#     city_name=city_data["name"]+"市"
#     city_confirm=city_data["total"]["confirm"]
#     data_list.append((city_name,city_confirm))
#
# print(data_list)
# data_list.append(("济源市",5))
# map=Map()
# map.add("河南省疫情图",data_list,"河南")
# map.set_global_opts(
#     title_opts=TitleOpts(title="河南疫情地图"),
#     visualmap_opts=VisualMapOpts(
#         is_show=True,
#         is_piecewise=True,
#         pieces=[
#             {"min":1,"max":50,"color":"#CCFFFF"},
#             {"min":51,"max":99,"color":"#FFFF99"},
#             {"min":100,"max":150,"color":"#FF9966"},
#             {"min":151,"max":200,"color":"#FF6666"},
#             {"min":201,"max":250,"color":"#CC3333"},
#             {"min":251,"color":"#990033"},
#         ]
#     )
# )
# map.render("河南疫情地图.html")
#